<template>
  <el-col :span="span"
          :xs="spanMap.xs"
          :sm="spanMap.sm"
          :md="spanMap.md"
          :lg="spanMap.lg"
          :xl="spanMap.xl"
          :style="descriptionsItem">
    <div :style="descriptionsItemContent">
      <div :style="descriptionsItemLabel">{{ label }}：</div>
      <div :style="expand ? descriptionsItemValue : descriptionsItemValueHide">
        <slot v-if="$slots.content"
              name="content" />
        <div v-else
             :style="expand ? defaultValue : defaultValueHide"
             :title="value">
          {{ value || "--" }}
        </div>
      </div>
    </div>
  </el-col>
</template>

<script>
export default {
  name: "DescriptionItem",
  props: {
    spanMap: {
      type: Object,
      required: false,
      default: () => {
        return {};
      }
    },
    span: {
      type: Number,
      required: false,
      default: 24
    },
    label: {
      type: String,
      required: true
    },
    value: {
      type: String,
      required: false,
      default () {
        return "";
      }
    },
    expand: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    descriptionsItem () {
      return {
        paddingBottom: "16px",
        paddingRight: "20px"
      }
    },
    descriptionsItemContent () {
      return {
        display: "flex",
        justifyContent: "flex-start",
        alignItems: "center",
        color: "#000",
        fontSize: "14px",
        lineHeight: 1.5,
        width: "100%",
        fontWeight: 400

      }
    },
    descriptionsItemLabel () {
      return {
        width: "140px",
        textAlign: "right",
        flexGrow: 0,
        flexShrink: 0,
        color: "#6e6e6e",
        fontWeight: 400,
        fontSize: "14px",
        lineHeight: 1.5

      }
    },
    descriptionsItemValueHide () {
      return {
        flexGrow: 1,
        overflow: "hidden"
      }
    },
    descriptionsItemValue () {
      return {
        flexGrow: 1,
        // overflow: "hidden"
      }
    },
    defaultValueHide () {
      return {
        width: "99%",
        overflow: "hidden",
        textOverflow: "ellipsis",
        whiteSpace: "nowrap"
      }
    },
    defaultValue () {
      return {
        width: "99%",
        overflow: "hidden",
        textOverflow: "ellipsis",
        // whiteSpace: "nowrap"
      }
    }
  }
};
</script>

<style scoped lang="scss">
.descriptions-item {
  padding-bottom: 16px;
  padding-right: 20px;
  span {
    display: inline-block;
  }
  .descriptions-item-content {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    color: #000;
    font-size: 14px;
    line-height: 1.5;
    width: 100%;
    font-weight: 400;
    .descriptions-item-label {
      width: 120px;
      text-align: right;
      flex-grow: 0;
      flex-shrink: 0;
      color: var(--prev-color-text-silvergrey);
      font-weight: 400;
      font-size: 14px;
      line-height: 1.5;
    }
    .descriptions-item-value {
      flex-grow: 1;
      overflow: hidden;
      .default-value {
        width: 99%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }
  }
}
</style>
